/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxUpgrade;
/*     */ import com.zimbra.cs.mailbox.MigrateToDocuments;
/*     */ import com.zimbra.cs.service.mail.CalendarUtils;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MigrateAccount
/*     */   extends AdminDocumentHandler
/*     */ {
/*  39 */   private static final String[] TARGET_ACCOUNT_PATH = { "migrate", "id" };
/*     */   
/*     */   protected String[] getProxiedAccountPath()
/*     */   {
/*  43 */     return TARGET_ACCOUNT_PATH;
/*     */   }
/*     */   
/*     */   private static enum Action {
/*  47 */     bug72174, 
/*  48 */     bug78254, 
/*  49 */     contactGroup, 
/*  50 */     wiki;
/*     */     
/*     */     private Action() {}
/*     */     
/*  54 */     private static Action fromString(String str) throws ServiceException { try { return valueOf(str);
/*     */       } catch (IllegalArgumentException e) {
/*  56 */         throw ServiceException.INVALID_REQUEST("invalid action " + str, e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  63 */     return false;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  68 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  69 */     Element migrate = request.getElement("migrate");
/*  70 */     Action action = Action.fromString(migrate.getAttribute("action"));
/*     */     
/*  72 */     String id = migrate.getAttribute("id");
/*     */     
/*  74 */     Provisioning prov = Provisioning.getInstance();
/*  75 */     Account account = prov.getAccountById(id);
/*  76 */     if (account == null) {
/*  77 */       throw AccountServiceException.NO_SUCH_ACCOUNT(id);
/*     */     }
/*     */     
/*  80 */     checkAdminLoginAsRight(zsc, prov, account);
/*     */     
/*  82 */     switch (action) {
/*     */     case contactGroup: 
/*  84 */       migrateContactGroup(account);
/*  85 */       break;
/*     */     case wiki: 
/*  87 */       migrateWiki(account);
/*  88 */       break;
/*     */     case bug72174: 
/*  90 */       migrateCalendar(account);
/*  91 */       break;
/*     */     case bug78254: 
/*  93 */       migrateFlagsAndTags(account);
/*  94 */       break;
/*     */     default: 
/*  96 */       throw ServiceException.INVALID_REQUEST("unsupported action " + action.name(), null);
/*     */     }
/*     */     
/*  99 */     return zsc.createElement(AdminConstants.MIGRATE_ACCOUNT_RESPONSE);
/*     */   }
/*     */   
/*     */   private void migrateContactGroup(Account account) throws ServiceException {
/* 103 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/* 104 */     if (mbox == null) {
/* 105 */       throw ServiceException.INVALID_REQUEST("no mailbox", null);
/*     */     }
/*     */     
/* 108 */     MailboxUpgrade.migrateContactGroups(mbox);
/*     */   }
/*     */   
/*     */   private void migrateFlagsAndTags(Account account) throws ServiceException {
/* 112 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/* 113 */     if (mbox == null) {
/* 114 */       throw ServiceException.INVALID_REQUEST("no mailbox", null);
/*     */     }
/* 116 */     MailboxUpgrade.migrateFlagsAndTags(mbox);
/*     */   }
/*     */   
/*     */   private void migrateWiki(Account account) throws ServiceException {
/* 120 */     MigrateToDocuments toDoc = new MigrateToDocuments();
/* 121 */     toDoc.handleAccount(account);
/*     */   }
/*     */   
/*     */   private void migrateCalendar(Account account) throws ServiceException {
/* 125 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/* 126 */     if (mbox == null) {
/* 127 */       throw ServiceException.INVALID_REQUEST("no mailbox", null);
/*     */     }
/*     */     
/* 130 */     CalendarUtils.migrateAppointmentsAndTasks(mbox);
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 135 */     relatedRights.add(Rights.Admin.R_adminLoginAs);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/MigrateAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */